package day12.demo2;

/**
 * @Auther:小陈的Java
 */
public class ThreadDemo3 extends Thread{
    public static void main(String[] args) throws Exception{
        QuickTrain quickTrain = new QuickTrain();
        GreenTrain greenTrain = new GreenTrain(quickTrain);
        quickTrain.start();
        greenTrain.start();
        Thread.sleep(4000);
        System.out.println("绿皮车状态："+greenTrain.getState());
        System.out.println("快车状态："+quickTrain.getState());
    }
}
class GreenTrain extends Thread{
    private QuickTrain quickTrain;
    public GreenTrain(QuickTrain quickTrain){
        this.quickTrain = quickTrain;
    }


    @Override
    public void run() {
        try {
            System.out.println("绿皮车：还有3s到达交叉口");
            Thread.sleep(3000);
            quickTrain.join();
            System.out.println("绿皮车：我先到，我不走，我等你，不见不散");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class QuickTrain extends Thread{
    @Override
    public void run() {
        try {
            System.out.println("快车：还有10秒到达交叉口");
            Thread.sleep(10000);
            System.out.println("快车：等我先走，不然压死你");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}//TODO 阻塞状态在day13